var projectId;
//初始化
$(function () {
	projectId = getProjectUrlParam("projectId", "project");
	$("#projectId").val(projectId);
    gridObj = $.fn.bsgrid.init('g_tabYeh', {
        dataType: 'json',
        ajaxType: 'get',
        url: server_url+'/rest/projectStaff/list.do?token='+token+'&ran='+Math.random(),
        otherParames:{'projectId': projectId},
        autoLoad: true,
        pageSizeSelect: true,
        stripeRows: true,
        pageSize: 10,
        displayBlankRows: false,
        isProcessLockScreen:true,
        rowSelectedColor:false
    });
    $('#qx').append('<span style="padding-left:5px;">全选</span>');
});

//添加操作项信息
function operate(record, rowIndex, colIndex, options) {
	return '<a href="javascript:edit(\''
			+ gridObj.getRecordIndexValue(record, 'id')
			+ '\');">编辑</a><a href="javascript:getInfo(\''
			+ gridObj.getRecordIndexValue(record, 'id')
			+ '\');">个人详情</a>';
}
// 获取checkbox选中
function deleteByIds() {
	var ids = gridObj.getCheckedValues('id').toString();
	if (ids == "") {
		easyDialog.open({
			container:{
				header:"温馨提示",
				content:"请选择要操作的记录！"
			},
			autoClose : 1000
		});
	} else {
		easyDialog.open({
			  container : {
				header:"温馨提示",
			    content : '您确定要删除吗？',
			    yesFn : function(){
			    	$.ajax({
			    		url : server_url+'/rest/projectStaff/delete.do?token='+token+'&ran='+Math.random(),
						type : 'post',
						dataType : 'json',
						data : {
							ids : ids
						},
						success : function(data) {
							if (data.retCode = "0000") {
								var url = "projectStaffList.do?ran="+Math.random();
								tl_config.loadToWorkArea(url);
							}else{
								easyDialog.open({
									container:{
										header:"温馨提示",
										content:data.retMsg
									},
									autoClose : 1000
								});
							}
						}
					});
			    },
			    noFn : true
			  }
		});
	}
}
// 查询
function search() {
	if(checkForm('myform')){
		return;
	}
	searchParames = $('#myform').serialize();
	if ($('#projectName').val() == '') {
		gridObj.search('');
	} else {
		gridObj.search(searchParames);
	}
}
// 添加
function add() {
	var url = "projectStaffAdd.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
// 编辑
function edit(id) {
	var url = "projectStaffEdit.do?id="+id+"&ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
// 删除
function del() {
	deleteByIds();
}
// 详情
function getInfo(id) {
	var url = "projectStaffInfo.do?id="+id+"&ran="+Math.random();
	tl_config.loadToWorkArea(url);
}
//导入
function importStaff() {
	var file=$("#file");
    if($.trim(file.val())==''){
    	easyDialog.open({
			container:{
				header:"温馨提示",
				content:"请选择导入文件！"
			},
			autoClose : 1000
		});
    	return false;
    }
    if(checkForm('fileform')){
		return;
	}
	var addUser = $("#addUser").val();
	easyDialog.open({
		  container : {
			  header:"温馨提示",
		    content : '您确定要导入吗？',
		    yesFn : function(){
		    	$.ajaxFileUpload({
		    		url : server_url+'/rest/projectStaff/importStaff.do?token='+token+'&projectId='+projectId+'&addUser='+addUser+'&ran='+Math.random(),
					type : 'post',
					dataType:'json',
					secureuri : false,  
					fileElementId:['file'],
					success : function(data) {
						if(data.retCode == "0001"){
							easyDialog.open({
								container:{
									header:"温馨提示",
									content:data.retMsg+"条记录没有导入成功！"
								},
								autoClose : 2000
							});
						}
						var url = "projectStaffList.do?ran="+Math.random();
						tl_config.loadToWorkArea(url);
					}
				});
		    },
		    noFn : true
		  }
	});
}


